package com.yunxi.controller.sat;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sat.pojo.SatTestDriveRouteVO;
import com.yunxi.sat.service.SatTestDriveRouteDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 试乘试驾路线 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-07-09
 */
@RestController
@RequestMapping("/admin/satTestDriveRoute")
@Api(tags = "sat:testDriveRoute", description = "试乘试驾路线接口")
public class SatTestDriveRouteController {
 private static final Logger logger = LoggerFactory.getLogger(SatTestDriveRouteController.class);

 @Autowired
 SatTestDriveRouteDubboService satTestDriveRouteDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "查询分页")
 @ApiImplicitParams({
         @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
 })
 public ApiResult page(SatTestDriveRouteVO satTestDriveRouteVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
     if(loginInfo != null){
         satTestDriveRouteVO.setPartnerCode(loginInfo.getPartnerCode());
     }else return ResponseUtil.fail401();

     return ResponseUtil.ok(satTestDriveRouteDubboService.findPageByVO(satTestDriveRouteVO, pageNum, pageSize));
 }

 @GetMapping("/list")
 @ApiOperation(value = "查询列表")
 public ApiResult list(@CurrentUser LoginInfo loginInfo) throws Exception {
     return ResponseUtil.ok(satTestDriveRouteDubboService.listByCode(loginInfo.getPartnerCode()));
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 @ApiImplicitParam(paramType="query", name = "testDriveRouteId", value = "主键id", required = true, dataType = "String")
 public ApiResult load(String testDriveRouteId) throws Exception {
     return ResponseUtil.ok(satTestDriveRouteDubboService.getById(testDriveRouteId));
 }

 @PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody SatTestDriveRouteVO satTestDriveRouteVO, @CurrentUser LoginInfo loginInfo) throws Exception {
     if(loginInfo != null){
         satTestDriveRouteVO.setPartnerCode(loginInfo.getPartnerCode());
     }else return ResponseUtil.fail401();
     satTestDriveRouteVO.setCreateBy(loginInfo.getUserCode());
     satTestDriveRouteVO.setUpdateBy(loginInfo.getUserCode());
     satTestDriveRouteDubboService.saveOrUpdate(satTestDriveRouteVO);
     return ResponseUtil.ok("success");
 }

 @PostMapping("/del")
 @ApiOperation(value = "删除")
 public ApiResult del(@RequestBody @ApiParam(value = "主键id集合") List<String> list,@CurrentUser LoginInfo loginInfo) throws Exception {
     satTestDriveRouteDubboService.removeRoute(list,loginInfo.getUserCode());
     return ResponseUtil.ok("success");
 }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(satTestDriveRouteDubboService.findMapByList(params));
}*/
}
